Skip to content

fix: supervise non-coroutine observer Awaitables safely - #194

Merged
frostming merged 8 commits into
agentclientprotocol:mainfrom
anishpentyala:fix/observer-awaitable-adapters
Nov 25, 2026
Merged

frostming merged 8 commits into
agentclientprotocol:mainfrom
anishpentyala:fix/observer-awaitable-adapters

Conversation

@anishpentyala

@anishpentyala anishpentyala commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Accept non-coroutine Awaitable results from stream observers without raising TypeError during notification delivery.

TaskSupervisor.create accepts Awaitable values but passes them directly to asyncio.create_task, which requires a coroutine on the supported Python versions. Keep native coroutines scheduled directly and wrap other Awaitables with the small _await_result coroutine. The supervised result remains a Task.

This revision follows the review request to keep the fix narrow. It removes the adoption map, dependency traversal and additional shutdown behavior from the earlier version. It adds no cancellation-ownership, cancellation-before-start, foreign-loop validation or dependency-cycle guarantees. Existing shutdown behavior is unchanged.

Regression test

One Future-returning outgoing observer test checks that notification delivery succeeds and the peer receives the message. The same test fails on the original base with TypeError because the observer returns a pending Future. No production-incident claim is made.

Validation

  • Python 3.10.12 full suite with doctests: 540 passed, 2 skipped.
  • Python 3.13.18 and 3.15.2 full suite with doctests: 541 passed, 1 skipped each.
  • make check: passed, including locked dependencies, pre-commit, type checking and dependency checks.
  • Build passed; the retained regression also passed against a fresh installed wheel outside the checkout on Python 3.15.2.

The skips are the optional Gemini check and, on Python 3.10, the existing eager-task-factory test requiring Python 3.12+. Existing codegen/deprecation warnings remain. The first formatting check reformatted one line; the final check passed.

No schema regeneration, dependency change or public-signature change.

Preserve Task return and error-handler contracts, caller Task names, cancellation adoption and reentrant shutdown safety through explicit same-supervisor adoption edges.
Add tests for observer awaitables to ensure proper JSON-RPC delivery and error handling.
Add tests for TaskSupervisor and Connection closure behavior.

@frostming frostming left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too complex IMO. Wrapping non-coroutine awaitables with _await_result is enough to fix the TypeError; please drop the adoption map and _awaits_task, and keep a single test for a Future-returning observer.

@anishpentyala

Copy link
Copy Markdown
Contributor Author

Thanks, narrowed this to _await_result for non-coroutine Awaitables and one Future-returning observer test. Removed the adoption map, _awaits_task and the extra shutdown tests. The regression fails with the original TypeError on the base and passes with the change. Full tests and make check pass, and the description now reflects the narrower scope.

@frostming
frostming merged commit d9a8676 into agentclientprotocol:main Nov 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants